#include "action_common.h"
#include "primitive.h"

namespace FD
{
	namespace Action
	{
		Create::Create(Position *pos, Primitive::Base *obj) : m_primitive(obj)
		{
			m_position.next = pos;
			m_position.prev = pos->prev;
			m_position.elem = obj;
		}

		Create::~Create()
		{
		}

		void Create::apply()  
		{
			m_position.prev->next = &m_position;
			m_position.next->prev = &m_position;
		}

		void Create::revert() 
		{
			m_position.prev->next = m_position.next;
			m_position.next->prev = m_position.prev;
		}

		// =====================================================================

		Delete::Delete(Position *pos) : m_position(pos)
		{
		}

		Delete::~Delete()
		{
		}

		void Delete::apply()  
		{
			m_position->prev->next = m_position->next;
			m_position->next->prev = m_position->prev;
		}

		void Delete::revert() 
		{
			m_position->prev->next = m_position;
			m_position->next->prev = m_position;
		}
	}
}